<?php include('app/admin/welcome/html/meta.html');?>
<?php include('app/admin/welcome/html/header.html');?>
<?php include('app/admin/welcome/html/menu.html');?>

<section class="Hui-article-box">
	<nav class="breadcrumb"><i class="Hui-iconfont"></i>
		<a href="/" class="maincolor">首页</a>
		<span class="c-999 en">&gt;</span>
		<span class="c-666">管理员添加</span>
		<a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a>
	</nav>
	<div class="Hui-article">

		<article class="page-container">
			<form class="form form-horizontal" id="form-article-add" method="post" action="#" >
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-2"><span class="c-red"></span>账号：</label>
					<div class="formControls col-xs-6 col-sm-7">
						<input type="text" class="input-text" value="" placeholder="" id="username" name="username">
						<span ></span>
					</div>
					<div id="usernametick" style="color: red;" class="formControls col-xs-2 col-sm-2"></div>
				</div>
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-2"><span class="c-red"></span>密码：</label>
					<div class="formControls col-xs-6 col-sm-7">
						<input type="password" class="input-text" value="" placeholder="" id="password" name="password">
					</div>
					<div id="passwordtick" style="color: red;" class="formControls col-xs-2 col-sm-2"></div>
				</div>
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-2"><span class="c-red"></span>确认密码：</label>
					<div class="formControls col-xs-6 col-sm-7">
						<input type="password" class="input-text" value="" placeholder="" id="psd_confirm" name="psd_confirm">
					</div>
					<div id="psd_confirmtick" style="color: red;" class="formControls col-xs-2 col-sm-2"></div>
				</div>
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-2"><span class="c-red"></span>管理员级别：</label>
					<div class="formControls col-xs-6 col-sm-7"> 
						<span class="select-box">
							<select id="role_id" class="select">
								<?php foreach($role as $k=>$v){?>
									<option value="<?php echo $v['Id'];?>"><?php echo $v['name'];?></option>
								<?php }?>
							</select>
						</span> 
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-2"><span class="c-red"></span>性别：</label>
					<div class="formControls col-xs-6 col-sm-7"> 
						<span class="select-box">
							<select id="sex" class="select">
								<option value="男">男</option>
								<option value="女">女</option>
							</select>
						</span> 
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-2"><span class="c-red"></span>昵称：</label>
					<div class="formControls col-xs-6 col-sm-7">
						<input type="text" class="input-text" value="" placeholder="" id="nickname" name="nickname">
					</div>
					<div id="nicknametick" style="color: red;" class="formControls col-xs-2 col-sm-2"></div>
				</div>
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-2"><span class="c-red"></span>电话：</label>
					<div class="formControls col-xs-6 col-sm-7">
						<input type="text" class="input-text" value="" placeholder="" id="tel" name="tel">
					</div>
					<div id="teltick" style="color: red;" class="formControls col-xs-2 col-sm-2"></div>
				</div>
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-2"><span class="c-red"></span>邮箱：</label>
					<div class="formControls col-xs-6 col-sm-7">
						<input type="email" class="input-text" value="" placeholder="" id="email" name="email">
					</div>
					<div id="emailtick" style="color: red;" class="formControls col-xs-2 col-sm-2"></div>
				</div>
				<div class="row cl">
					<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
						<button  id="submit" class="btn btn-primary radius" type="submit"><i class="Hui-iconfont">&#xe632;</i> 保存并提交</button>
						<button id="mm" class="btn btn-default radius" type="reset">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
					</div>
				</div>
			</form>
		</article>
	</div>
</section>

<?php include('app/admin/welcome/html/footer.html');?>

<!--请在下方写此页面业务相关的脚本-->

<!-- 配置文件 -->
<script type="text/javascript" src="static/lib/ueditor/1.4.3/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="static/lib/ueditor/1.4.3/ueditor.all.js"></script>
<!-- 实例化编辑器 -->
<script type="text/javascript">
    var ue = UE.getEditor('container');
    
    //账号格式判断
    $('#username').blur(function(){
    	var usernames = $('#username').val();
		if(usernames == '')
		{
			$('#usernametick').text('账号不能为空！');
			return false;
		}else
		{
			$('#usernametick').text('');
			var reg = /^[a-zA-Z]{1}\w{7,17}$/;
			var name_result = reg.exec(usernames);
			if(name_result == null)
			{
				$('#usernametick').text('账号不能以数字开头，长度必须为8-18位,请重新输入！');
				return false;
			}else
			{
				$('#usernametick').text('');
				$.get('index.php?a=admin&b=maneger&c=add&username_flag=selct',
					{username:usernames},function(date){
					if(date == 12001)
					{
						$('#usernametick').text('');
		    			$('#usernametick').text('账号已存在！');
		    			return false;
					}else 
					{
						$('#usernametick').text('');
						return false;
					}
				})
			}
		}
    })
    
    //密码格式判断
    $('#password').blur(function(){
    	var password = $(this).val();
		if(password == '')
		{
			$('#passwordtick').text('密码不能为空！');
			return false;
		}else
		{
			$('#passwordtick').text('');
			return false;
		}		
    })
    
    //确认密码格式判断
    $('#psd_confirm').blur(function(){
    	var psd_confirm = $(this).val();
    	var password = $('#password').val();
    	switch(psd_confirm)
    	{
    		case '':
    			$('#psd_confirmtick').text('');
    			$('#psd_confirmtick').text('密码不能为空！');
    		break;
    		case password:
    			$('#psd_confirmtick').text('');
    		break;
    		default:
    			$('#psd_confirmtick').text('');
    			$('#psd_confirmtick').text('密码不一致，请重新输入！');
    	}	
    })
    
    //昵称格式判断
    $('#nickname').blur(function(){
    	var nicknames = $(this).val();
		$.get('index.php?a=admin&b=maneger&c=add&nickname_flag=selct',
			{nickname:nicknames},function(date){
			if(date == 12001)
			{
				$('#nicknametick').text('');
    			$('#nicknametick').text('昵称已存在！');
    			return false;
			}else 
			{
				$('#nicknametick').text('');
				return false;
			}
		})
  	})
    
    //电话格式判断
    $('#tel').blur(function(){
    	var tel = $(this).val();
		if(tel == '')
		{
			$('#teltick').text('电话不能为空！');
			return false;
		}else
		{
			$('#tel').text('');
			var reg = /^\d{7,11}$/;
			var tel_result = reg.exec(tel);
			if(tel_result == null)
			{
				$('#teltick').text('电话号码格式有误,请重新输入！');
				return false;
			}else
			{
				$('#teltick').text('');
				return false;
			}
			return false;
		}
	})


    $('#submit').click(function(){
//  	alert(11);return false;
		var urls = 'index.php?a=admin&b=maneger&c=add';	
		var username = $('#username').val();
		var password = $('#password').val();
		var psd_confirm = $('#psd_confirm').val();
		var role_id = $('#role_id').val();
		var sex = $('#sex').val();
		var nickname = $('#nickname').val();
		var tel = $('#tel').val();
		var email = $('#email').val();
		
		var usernametick = $('#usernametick').text();
		var passwordtick = $('#passwordtick').text();
		var psd_confirmtick = $('#psd_confirmtick').text();
		var nicknametick = $('#nicknametick').text();
		var teltick = $('#teltick').text();
		
//		console.log(usernametick);
//		console.log(passwordtick);
//		console.log(psd_confirmtick);
//		console.log(nicknametick);
//		console.log(teltick);
//		return false;
		if(
			username != '' &&
			password != '' &&
			psd_confirm != '' &&
			nickname != '' &&
			tel != '' &&
			email != '' &&
			usernametick == ''&&
			passwordtick == ''&&
			psd_confirmtick == ''&&
			nicknametick == ''&&
			teltick == ''
		)
		{
			$.post(urls,
			{
				username:username,
				password:password,
				role_id:role_id,
				sex:sex,
				nickname:nickname,
				tel:tel,
				email:email
			},
			function(date){
				if(date == 10086)
				{
					alert('添加成功');
					window.location = 'index.php?a=admin&b=maneger&c=index';
					return false;
				}else if(date == 10087)
				{
					alert('添加失败');
					return false;
				}
			})
		}else
		{
			alert('信息有误，请重新输入！');
			return false;	
		}
		return false;
	})
    
     
        
        
</script>
<!--/请在上方写此页面业务相关的脚本-->

</body>

</html>